import * as api from '../../api/permisson'
import allRoutes from '../../router/generateRoute'
let routes = allRoutes.find(route =>route.name === "home")
import recursion from '@/router/recursionRoutes'
import dynamicRoute from '@/router/dynamicRoutes'
import router from '@/router'


export default {
    namespaced:true,
    state: {
        useMens:[]
    },
    getters: {},
    mutations: {
        SETDATOSTA(state,payload){
            state.useMens = [...payload]
            dynamicRoute.children = [...dynamicRoute.children, ...payload]
            router.addRoute(dynamicRoute)
        },


        
    },
    actions: {
        GETDG({commit}){
            return api.getMenuList()
            .then(res =>{
                // console.log('res---',res.data.menuList)
                let useMens = recursion(res.data.menuList,routes.children)
                commit('SETDATOSTA',useMens)

            })
        }
    },
    modules: {},
  }